<?php
	$mode=$_GET['mode'];
	$obj=new Post();
	$obj->PostID=$_POST['PostID'];
	$obj->NewsTypeID=$_POST['NewsTypeID'];
	$obj->Title=$_POST['Title'];
	$obj->Summary=$_POST['Summary'];
	$obj->Detail=$_POST['Detail'];
	$obj->TitleEng=$_POST['TitleEng'];
	$obj->SummaryEng=$_POST['SummaryEng'];
	$obj->DetailEng=$_POST['DetailEng'];
	$obj->ImageID=$_POST['imageid'];
	$obj->ImagePath=$_POST['imagepath'];
	$obj->Source=$_POST['Source'];
	$obj->Price=$_POST['Price'];
	$obj->Status=arrayToRefer($_POST['ArrStatus']);
	
	if($_POST['PostID']=="")
	{
		$obj->insert($conn);
		
	}
	else
	{
		$obj->update($conn);
		
	}
	
	$obj->updateImage($conn);
	//Update color
	$ID=$_POST['ID'];
	$ColorName=$_POST['ColorName'];
	$Icon=$_POST['Icon'];
	$IconPath=$_POST['IconPath'];
	$ImageColor=$_POST['ImageColor'];
	$ImageColorPath=$_POST['ImageColorPath'];
	$Group=$_POST['Group'];
	$color = new Color($conn);
	foreach($Icon as $key => $item)
	{
		$data['ID'] = $ID[$key];;
		$data['ItemID'] = $obj->PostID;
		$data['ColorName'] = $ColorName[$key];
		$data['Icon'] = $Icon[$key];
		$data['IconPath'] = $IconPath[$key];
		$data['ImageID'] = $ImageColor[$key];
		$data['ImagePath'] = $ImageColorPath[$key];
		$data['`Group`'] = $Group[$key];
		
		if($data['ID']=="")
		{
			$color->insert($data);
		}
		else
		{
			$color->update($data);
		}
	}
	//Remove color
	$del = $_POST['delcolor'];
	if(count($del))
	{
		foreach($del as $item)
		{
			$color->delete($item);
		}
	}
	
	if($mode=="del")
	{
		$obj->PostID=$id;
		$obj->delete($conn);
	}
	$url="?module=product&type=".$obj->NewsTypeID."&page=".$_SESSION['currentpage'];
	echo "<script language='JavaScript'> window.location = '".$url."'</script>";
?>